<template>
  <div class="user-settings">
    <div class="settings-content">
      <!-- 隐私设置 -->
      <el-card class="settings-card">
        <template #header>
          <div class="card-header">
            <div class="title-section">
              <el-icon class="title-icon"><Lock /></el-icon>
              <span class="card-title">隐私设置</span>
            </div>
          </div>
        </template>

        <div class="privacy-settings">
          <div class="privacy-section">
            <h3 class="section-title">
              <el-icon><User /></el-icon>
              个人资料隐私
            </h3>
            <div class="privacy-grid">
              <div class="privacy-item">
                <div class="privacy-info">
                  <div class="privacy-icon profile">
                    <el-icon><User /></el-icon>
                  </div>
                  <div class="privacy-content">
                    <h4>个人资料可见性</h4>
                    <p>控制其他用户可以看到您的哪些信息</p>
                  </div>
                </div>
                <el-select 
                  v-model="privacySettings.profileVisibility" 
                  placeholder="请选择"
                  size="large"
                  class="privacy-select"
                >
                  <el-option label="🌐 公开" value="public" />
                  <el-option label="👥 仅好友可见" value="friends" />
                  <el-option label="🔒 仅自己可见" value="private" />
                </el-select>
              </div>

              <div class="privacy-item">
                <div class="privacy-info">
                  <div class="privacy-icon post">
                    <el-icon><Document /></el-icon>
                  </div>
                  <div class="privacy-content">
                    <h4>帖子可见性</h4>
                    <p>控制您发布的帖子的可见范围</p>
                  </div>
                </div>
                <el-select 
                  v-model="privacySettings.postVisibility" 
                  placeholder="请选择"
                  size="large"
                  class="privacy-select"
                >
                  <el-option label="🌐 公开" value="public" />
                  <el-option label="👥 仅好友可见" value="friends" />
                  <el-option label="🔒 仅自己可见" value="private" />
                </el-select>
              </div>

              <div class="privacy-item">
                <div class="privacy-info">
                  <div class="privacy-icon online">
                    <el-icon><CircleCheck /></el-icon>
                  </div>
                  <div class="privacy-content">
                    <h4>在线状态显示</h4>
                    <p>是否向其他用户显示您的在线状态</p>
                  </div>
                </div>
                <el-switch
                  v-model="privacySettings.showOnlineStatus"
                  size="large"
                  class="privacy-switch"
                  active-text="显示"
                  inactive-text="隐藏"
                  style="--el-switch-on-color: #67c23a;"
                />
              </div>
            </div>
          </div>

          <div class="privacy-section">
            <h3 class="section-title">
              <el-icon><ChatDotRound /></el-icon>
              社交互动隐私
            </h3>
            <div class="privacy-grid">
              <div class="privacy-item">
                <div class="privacy-info">
                  <div class="privacy-icon message">
                    <el-icon><ChatDotRound /></el-icon>
                  </div>
                  <div class="privacy-content">
                    <h4>私信接收</h4>
                    <p>控制谁可以向您发送私信</p>
                  </div>
                </div>
                <el-select 
                  v-model="privacySettings.messageSetting" 
                  placeholder="请选择"
                  size="large"
                  class="privacy-select"
                >
                  <el-option label="所有人" value="everyone" />
                  <el-option label="仅好友" value="friends" />
                  <el-option label="不允许" value="none" />
                </el-select>
              </div>

              <div class="privacy-item">
                <div class="privacy-info">
                  <div class="privacy-icon search">
                    <el-icon><Search /></el-icon>
                  </div>
                  <div class="privacy-content">
                    <h4>搜索可见性</h4>
                    <p>是否允许其他用户通过搜索找到您</p>
                  </div>
                </div>
                <el-switch
                  v-model="privacySettings.searchable"
                  size="large"
                  class="privacy-switch"
                  active-text="允许"
                  inactive-text="禁止"
                />
              </div>
            </div>
          </div>
        </div>

        <div class="privacy-actions">
          <el-button 
            type="primary" 
            @click="savePrivacySettings" 
            :loading="savingPrivacy"
            size="large"
            class="save-btn"
          >
            <el-icon><Check /></el-icon>
            保存隐私设置
          </el-button>
          <el-button 
            @click="resetPrivacySettings"
            size="large"
            class="reset-btn"
          >
            <el-icon><Refresh /></el-icon>
            恢复默认
          </el-button>
        </div>
      </el-card>
    </div>
  </div>
</template>

<script setup>
import { ref, reactive } from 'vue'
import { ElMessage } from 'element-plus'
import { Lock, User, Document, CircleCheck, ChatDotRound, Search, Check, Refresh } from '@element-plus/icons-vue'

// 响应式数据
const savingPrivacy = ref(false)

// 隐私设置
const privacySettings = reactive({
  profileVisibility: 'public',
  postVisibility: 'public',
  showOnlineStatus: true,
  messageSetting: 'everyone',
  searchable: true
})

// 默认设置
const defaultPrivacySettings = { ...privacySettings }

// 方法
const savePrivacySettings = async () => {
  savingPrivacy.value = true
  try {
    // 模拟保存隐私设置API
    await new Promise(resolve => setTimeout(resolve, 1000))
    ElMessage.success({
      message: '隐私设置保存成功',
      type: 'success',
      showClose: true
    })
  } catch (error) {
    console.error('保存隐私设置失败:', error)
    ElMessage.error('保存失败')
  } finally {
    savingPrivacy.value = false
  }
}

const resetPrivacySettings = () => {
  Object.assign(privacySettings, defaultPrivacySettings)
  ElMessage.info('已恢复默认设置')
}
</script>

<style scoped>
.user-settings {
  width: 100%;
  padding: 24px;
  background: linear-gradient(135deg, #f5f7fa 0%, #e4e7ed 100%);
  min-height: 100vh;
}

.settings-content {
  max-width: 1000px;
  margin: 0 auto;
}

.settings-card {
  border-radius: 20px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
  border: none;
  overflow: hidden;
  background: white;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 24px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.title-section {
  display: flex;
  align-items: center;
  gap: 12px;
}

.title-icon {
  font-size: 24px;
  color: white;
}

.card-title {
  font-size: 20px;
  font-weight: 700;
  color: white;
  letter-spacing: 0.5px;
}

/* 隐私设置样式 */
.privacy-settings {
  padding: 8px 0;
}

.privacy-section {
  margin-bottom: 40px;
}

.section-title {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 18px;
  font-weight: 700;
  color: #2d3748;
  margin: 0 0 24px 0;
  padding: 16px 24px;
  background: linear-gradient(135deg, #f8f9ff 0%, #f0f2ff 100%);
  border-radius: 12px;
  border-left: 4px solid #667eea;
}

.section-title .el-icon {
  color: #667eea;
  font-size: 20px;
}

.privacy-grid {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 0 24px;
}

.privacy-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 28px;
  background: white;
  border-radius: 16px;
  border: 1px solid #f0f0f0;
  transition: all 0.3s ease;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}

.privacy-item:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1);
  border-color: #667eea;
}

.privacy-info {
  display: flex;
  align-items: center;
  gap: 20px;
  flex: 1;
}

.privacy-icon {
  width: 60px;
  height: 60px;
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  color: white;
  flex-shrink: 0;
}

.privacy-icon.profile {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.privacy-icon.post {
  background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
}

.privacy-icon.online {
  background: linear-gradient(135deg, #4ecdc4 0%, #44a08d 100%);
}

.privacy-icon.message {
  background: linear-gradient(135deg, #ffd89b 0%, #19547b 100%);
}

.privacy-icon.search {
  background: linear-gradient(135deg, #a8edea 0%, #fed6e3 100%);
  color: #2d3748;
}

.privacy-content h4 {
  margin: 0 0 8px 0;
  color: #2d3748;
  font-size: 18px;
  font-weight: 600;
}

.privacy-content p {
  margin: 0;
  color: #718096;
  font-size: 14px;
  line-height: 1.5;
}

.privacy-select {
  width: 200px;
}

.privacy-switch {
  transform: scale(1.1);
}

/* 操作按钮样式 */
.privacy-actions {
  text-align: center;
  padding: 32px 24px 8px;
  border-top: 1px solid #f0f0f0;
  margin-top: 24px;
  display: flex;
  gap: 16px;
  justify-content: center;
}

.save-btn {
  padding: 12px 32px;
  border-radius: 12px;
  font-weight: 600;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border: none;
}

.save-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(102, 126, 234, 0.4);
}

.reset-btn {
  padding: 12px 32px;
  border-radius: 12px;
  font-weight: 600;
  border: 1px solid #e2e8f0;
}

.reset-btn:hover {
  border-color: #667eea;
  color: #667eea;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .user-settings {
    padding: 16px;
  }
  
  .privacy-item {
    flex-direction: column;
    align-items: stretch;
    gap: 20px;
    padding: 24px;
  }
  
  .privacy-info {
    gap: 16px;
  }
  
  .privacy-icon {
    width: 50px;
    height: 50px;
    font-size: 20px;
  }
  
  .privacy-content h4 {
    font-size: 16px;
  }
  
  .privacy-content p {
    font-size: 13px;
  }
  
  .privacy-actions {
    flex-direction: column;
    gap: 12px;
  }
  
  .section-title {
    font-size: 16px;
    padding: 12px 20px;
  }
  
  .privacy-grid {
    padding: 0 16px;
  }
}
</style>